<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>冒泡</title>
</head>
<body>
<script>
    var arr=[3,5,8,7,5];
    function bubbleSort(arr){
        var length=arr.length;
        for(var i=0;i<length;i++){
            for(var j=0;j<length-1;j++){
                if(arr[j]>arr[j+1]){
                    var temp=arr[j+1];
                    arr[j+1]=arr[j];
                    arr[j]=temp;
                }
            }
        }
        console.log(arr);
        return arr;
    }
    bubbleSort(arr);

</script>
</body>
</html>